package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

public class OrdersController {

    // OrdersController/createOrders?userId=22222222222&businessId=10002&daId=16&orderTotal=23.0
    public int createOrders(HttpServletRequest request){
        int result = 0;
        String userId = request.getParameter("userId");
        Integer businessId = Integer.parseInt(request.getParameter("businessId"));
        Integer daId = Integer.parseInt(request.getParameter("daId"));
        Double orderTotal = Double.parseDouble(request.getParameter("orderTotal"));

        OrdersService ordersService = new OrdersServiceImpl();
        result = ordersService.createOrders(userId, businessId, daId, orderTotal);
        return result;
    }

    //  OrdersController/getOrdersById?orderId=9
    public Orders getOrdersById(HttpServletRequest request){
        Orders orders = null;
        Integer orderId = Integer.parseInt(request.getParameter("orderId"));
        OrdersService ordersService = new OrdersServiceImpl();
        orders = ordersService.getOrdersById(orderId);
        return orders;
    }

    //  OrdersController/listOrdersByUserId?userId=11111111111
    public List<Orders> listOrdersByUserId(HttpServletRequest request){
        List<Orders> ordersList = null;
        String userId = request.getParameter("userId");
        OrdersService ordersService = new OrdersServiceImpl();
        ordersList = ordersService.listOrdersByUserId(userId);
        return ordersList;
    }

}
